﻿Public Class ClassSupplier
    Public Shared Function addSupplier(ByVal name As String, ByVal phone As String, ByVal address As String, ByVal desc As String)
        Dim sql = "insert into tbl_supplier(supplier_name,phone,address,description,active) value(@name,@phone,@address,@desc,1)"
        Try
            Cmd.Parameters("@name") = name
            Cmd.Parameters("@phone") = phone
            Cmd.Parameters("@address") = address
            Cmd.Parameters("@desc") = desc
            Cmd.ExecuteNonQuery(sql)
            myMsgbox.show("Add new supplier sucess!!!", "New Supplier")
            Return True
        Catch ex As Exception
            myMsgbox.show("Add new supplier fail!!", "New Supplier")
            Return False
        End Try
    End Function
    Public Shared Function editSupplier(ByVal id As Integer, ByVal name As String, ByVal phone As String, ByVal address As String, ByVal desc As String)
        Dim sql = "update tbl_supplier set supplier_name=@name,phone=@phone,address=@address,description=@desc where supplier_id=@id"
        Try
            Cmd.Parameters("@id") = id
            Cmd.Parameters("@name") = name
            Cmd.Parameters("@phone") = phone
            Cmd.Parameters("@address") = address
            Cmd.Parameters("@desc") = desc
            Cmd.ExecuteNonQuery(sql)
            myMsgbox.show("Update Supplier Success!!!", "Update Supplier")
            Return True
        Catch ex As Exception
            myMsgbox.show("Update Supplier Fail!!!", "Update Supplier")
            Return False
        End Try
    End Function
    Public Shadows Function deleteSupplier(ByVal id As Integer)
        Dim sql = "update tbl_supplier set active=false where supplier_id=@id"
        Try
            Cmd.Parameters("@id") = id
            Cmd.ExecuteNonQuery(sql)

            myMsgbox.show("Delete Supplier Success!!!", "Delete Supplier")
            Return True
        Catch ex As Exception
            myMsgbox.show("Delete Supplier Fail!!!", "Delete Supplier")
            Return False
        End Try
    End Function

    Public Shared Function loadSupplier(ByVal text As String) As DataTable
        Dim sql = "select * from tbl_supplier where active=true"
        Try
            Dim dt As New DataTable
            dt = Cmd.ExecuteDataTable(sql)
            Return dt
        Catch ex As Exception
            Return Nothing
        End Try
    End Function
End Class
